#include<stdlib.h>
#include<unistd.h>
#include<stdio.h>

int main()
{
	int id = fork();
	if(id == 1)
	{
		printf("fork error");
	}
	else if(id == 0)
	{
		// getpid,getppid:通过系统调用获取当前进程和父进程的pid。另外还有通过环境变量获取pid的方式
		while(1)
		{
			printf("child pid is %d,parent pid is %d\n",getpid(),getppid());
			sleep(2);
		}
	}
	else{
		printf("father ppid is %d,child pid is %d\n",getppid(),getpid());
		exit(1);
	}

	return 0;
}
